package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

/**
 * @Author: JinboYang
 * @Description: 负责和dubbo交互
 * @Date: Created in 19:23 2021/1/4
 * @ModifiedBy:
 */
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    /**
     * @Description: 查询今日佳人
     * @Param:[userId]
     * @return:com.tanhua.server.vo.TodayBest
     * @Author:JinboYang
     * @Date:2021/1/4
     */
    public TodayBest queryTodayBest(Long userId) {
        //根据传过来的id找到最大缘分值的推荐用户 如果为空直接返回null
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(userId);
        if (null == recommendUser) {
            return null;
        }
        TodayBest todayBest = new TodayBest();
        //设置推荐人的id
        todayBest.setId(recommendUser.getUserId());

        //获得缘分值 取整
        double score = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {

        return this.recommendUserApi.queryPageInfo(id, page, pagesize);
    }

    /**
       * @Description: /**
       * @Param:[userId, id]
       * @return:double
       * @Author:JinboYang
       * @Date:2021/1/13
       */
    public double queryScore(Long userId, Long id) {
        return this.recommendUserApi.queryScore(userId,id);
    }
}
